HomeDirect Bank - Readme File - Hints and Tips
Welcome to HomeDirect! This Enterprise Java application uses J2EETM
technology, and is intended to be a design and development example to accompany the book
"Developing Enterprise Java Applications with J2EE and UML".
This document provides hints and tips for the J2EE 1.2 version of this example.
- What This Example Intends to Show
This example is meant to be complete enough to show how J2EE 1.2 technology components
work together to form a web-based application. At the same time, we wanted the example to
be simple enough so as to not get too lost in the details. This example uses:
- Stateless Session Beans
- Entity Beans with Container-Managed Persistence (CMP)
- JSP pages
- JavaBeans to pass info to JSP pages
- Examples of both successful transactions, and failed ones that require a rollback
- Login Page
There are 4 pre-defined users in this example. They are:
- guest1
- guest2
- cumrysh
- kahmed
You can login using any of these accounts, and they all use the same password 'pass'.
Characters are always case sensitive for usernames and passwords.
(If you wish to add new users, accounts, or other new data, you can do so following the instructions in
the next step.)
- Pre-defined Tables and Data
The example comes with pre-defined tables and data that you seed the database
with during the install process. If you would like to add data or modify any of the
existing data, simply edit the script file found at %HomeDirect%\sql\homedirect.sql
.
Modify any of the INSERT statements that you see in this file, but be careful
with the table creation calls (entity beans might no longer work if the tables are significantly changed).
Run %HomeDirect%\sql\Resetdb.bat
for the changes to take effect. You will
need to start back at the Login page after this database reset is done.
- J2EE Server Window Trace
This example has been compiled with trace statements added to the code in
certain key locations. When you run the application, the output of these trace statements will
appear in the J2EE server window. The trace can help you to understand the flow of
the code, as well as indicate EJB behavior in different situations.
- Simulated Remote System Failures
This example simulates successful and failed transactions. Whenever you Transfer Funds or Pay Bills, a
method
is called to allocate a reference id for the transaction. This method simulates
a failure if the current time on your local machine indicates the seconds are
between 0 and 5. For example, if the current time is 12:15:06, the transaction
is successful.
If the same transaction is done at 12:16:04, you will get a transaction failure
simulating a
problem with the remote system.
If the transaction succeeds, you will get back a valid reference id, and the trace
window should indicate that a COMMIT of the changes occurred for the EJBs involved
in the transaction. Account balances should reflect that the changes went through,
and a transaction record should appear.
Now take the same transaction, but in this case there was a simulated failure.
The logic here is setup such that most of the changes to the EJBs are done prior
to when the failure occurs. This way, you can see the rollback mechanism for these
EJBs in action. So, in the failure case you shouldn't see a COMMIT in the trace, and
account balances should return to what they were before the transaction started.
- Processing and Storage of Currency Values
You might notice in the example code that currency is always stored as an integer
value in the underlying database instead of as a decimal value. This is to avoid rounding
errors that occur when Java decimal values are automatically converted for storage in the
database format, and vice versa. Certain databases seem especially prone to such
problems with such conversions, so the approach used here ensures that the
calculations are valid..
To get around this issue, all dollar
values are converted to pennies, and this integer result is stored instead. This makes for a small amount of
conversion code to change values back and forth between pennies and dollars, but the results
of transactions are always correct using this method.
It's expected a established commercial databases will have fewer of these conversion problems. As well,
a more involved solution would be to have stored the decimal values as numerator and denominator
integer amounts instead, thus more easily allowing such conversions to work with any currency, not
just dollars and pennies.
- Container-Managed Persistence and the Sample J2EE Database
There is one last issue you should note when working with this release of J2EE.
It has been found that when working with Entity Beans using container-managed persistence,
the connection with the underlying database will only work correctly if the tables you
are dealing with have had their fields defined in alphabetical order. This
problem only appears to affect this release of J2EE, and only when using the
sample database that ships with it.
Keep this point in mind if you decide to expand on the database tables and Entity Beans
found in this example code. Again, commercial databases and enterprise application servers
are expected to not have this limitation.
Back to Install Instructions:
Install.html
Enter the HomeDirect Bank:
http://localhost:8000/homedirect/Login.jsp